package com.atguigu.newstestdemo.controller;

import com.atguigu.newstestdemo.entity.User;
import com.atguigu.newstestdemo.mapper.UserMapper;
import com.atguigu.newstestdemo.service.UserService;
import com.atguigu.newstestdemo.vo.GetPageUserListVo;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RequestMapping("/user/*")
@RestController
public class UserController {

    @Autowired
    UserService userService;

    @GetMapping("/deleteUserById")
    public void deleteByPrimaryKey(@RequestParam Long id){
        userService.deleteByPrimaryKey(id);
        System.out.println("接到deleteByPrimaryKey的id: "+id);
    }

    @PostMapping("/addUser")
    public void insert(@RequestBody User user) {
        userService.addUser(user);
        System.out.println("接到user表单: "+user);
    }

    public void insertSelective(User record) {

    }

    public User selectByPrimaryKey(Long id){
        return null;
    }

    @GetMapping("/getPageUserList")
    public ResponseEntity<GetPageUserListVo> getPageUserList(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                                             @RequestParam(value = "pageSize",defaultValue = "5") Integer pageSize) {
        GetPageUserListVo list = userService.selectAll(pageNum, pageSize);
        System.out.println("list表单: "+list);
        return ResponseEntity.ok(list);
    }


    public void updateByPrimaryKeySelective(User record) {

    }

    @PostMapping("/updateUser")
    public void updateByPrimaryKey(@RequestBody User record){
        userService.updateByPrimaryKey(record);
        System.out.println("接到updateByPrimaryKey表单: "+record);
    }

}
